import React, { Component, useState } from 'react';

// class State extends Component {
// 	state = {
// 		name: 'zy',
// 		age: 18
// 	}
// 	setAge = () => {
// 		this.setState({
// 			age: ++this.state.age
// 		})
// 	}
// 	render() {
// 		let { name, age } = this.state;
// 		return (<div>
// 			姓名:{name}<br />
// 			年龄:{age}
// 			<button onClick={this.setAge}>新增</button>
// 		</div>)
// 	}
// }

function State() {
	console.log(useState(18));
	//const [age, setAge] = useState(18);

	const [state, setState] = useState({
		name: 'zy',
		age: 18
	})

	const { name, age } = state;
	function setage() {
		console.log("age", age)
		setState({
			...state,
			age: age + 1
		});
	}
	function setname() {
		setState({
			...state,
			name: 'zhengyan'
		});
	}
	return (<div>
		姓名:{name}<br />
		年龄:{age}<br />
		<button onClick={setage}>新增</button>
		<button onClick={setname}>新增2</button>
	</div>)
}

export default State;